//
//  XTCReleasePersonInfomation.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/31.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XTCReleasePersonInfomation.h"
#import "XVVReleasePersonInfomation.h"
#import "XXTool.h"

@interface XTCReleasePersonInfomation ()

@property (nonatomic,strong) UILabel *releaseLabel;

@property (nonatomic,strong) XVVReleasePersonInfomation *informationView;

@property (nonatomic,strong) DKButton *bespeakButton;

@property (nonatomic,strong) DKButton *collectButton;

@end

@implementation XTCReleasePersonInfomation
{
    CGFloat informationViewHeight;
}

-(UILabel*)releaseLabel
{
    if (_releaseLabel==nil)
    {
        _releaseLabel = [[UILabel alloc] init];
        _releaseLabel.font = [XXTool systemFontOfSize:16.5f];
        _releaseLabel.textColor = [UIColor blackColor];
        _releaseLabel.text = NSLocalizedString(@"发布人", nil);
        [self addSubview:_releaseLabel];
    }
    return _releaseLabel;
}

-(XVVReleasePersonInfomation*)informationView
{
    if (_informationView==nil)
    {
        _informationView = [[XVVReleasePersonInfomation alloc] init];
        [self addSubview:_informationView];
    }
    return _informationView;
}

-(DKButton*)collectButton
{
    if (_collectButton==nil)
    {
        _collectButton = [[DKButton alloc] init];
        _collectButton.image = [UIImage imageNamed:@"收藏按钮_未点击"];
        _collectButton.text = NSLocalizedString(@"收藏", nil);
        _collectButton.imagePosition = DKButtonImagePositionAtBegan;
        [_collectButton setColor:[UIColor colorWithRed:158/255.0 green:159/255.0 blue:160/255.0 alpha:1.0] ForState:DKButtonStateNormal];
        _collectButton.font = [XXTool systemFontOfSize:14];
        _collectButton.imageSize = CGSizeMake(20, 20);
        _collectButton.imageTitleGap = 23.0f;
        [_collectButton setImageRenderingMode:DKButtonRenderingModeAlwaysOriginal];
        [_collectButton addTarget:self Select:@selector(clickCollectButton) ForEvent:DKButtonEventPressedEnd];
        [self addSubview:_collectButton];
    }
    return _collectButton;
}

-(DKButton*)bespeakButton
{
    if (_bespeakButton==nil)
    {
        _bespeakButton = [[DKButton alloc] init];
        _bespeakButton.image = [UIImage imageNamed:@"预约按钮_未点击"];
        _bespeakButton.text = NSLocalizedString(@"预约", nil);
        _bespeakButton.imagePosition = DKButtonImagePositionAtBegan;
        [_bespeakButton setColor:[UIColor colorWithRed:158/255.0 green:159/255.0 blue:160/255.0 alpha:1.0] ForState:DKButtonStateNormal];
        _bespeakButton.font = [XXTool systemFontOfSize:14];
        _bespeakButton.imageSize = CGSizeMake(20, 20);
        _bespeakButton.imageTitleGap = 23.0f;
        [_bespeakButton setImageRenderingMode:DKButtonRenderingModeAlwaysOriginal];
        [_bespeakButton addTarget:self Select:@selector(clickBespeakButton) ForEvent:DKButtonEventPressedEnd];
        [self addSubview:_bespeakButton];
        
    }
    return _bespeakButton;
}

-(void)initParameter
{
    
}

-(void)initUI
{
    [self releaseLabel];
    [self informationView];
    if ([UserInfo shareUserInfo].isExhibitor)
    {
        
    }
    else
    {
        [self collectButton];
        [self bespeakButton];
    }
}

-(void)refreshLayout:(CGRect)frame
{
    _releaseLabel.frame = CGRectMake(20
                                     , 10
                                     , frame.size.width-20
                                     , 20);
    _informationView.frame = CGRectMake(0, _releaseLabel.frame.size.height+_releaseLabel.frame.origin.y
                                        , frame.size.width
                                        , informationViewHeight);
    if ([UserInfo shareUserInfo].isExhibitor)
    {
        
    }
    else
    {
        _collectButton.frame = CGRectMake(0, _informationView.frame.size.height+_informationView.frame.origin.y
                                          , (frame.size.width-4)/2
                                          , 35);
        _bespeakButton.frame = CGRectMake(_collectButton.frame.size.width+_collectButton.frame.origin.x+4
                                          , _collectButton.frame.origin.y
                                          , _collectButton.frame.size.width
                                          , _collectButton.frame.size.height);
    }
    
}

-(void)clickCollectButton
{
    if ([_delegate respondsToSelector:@selector(releasePersonInfomationDidClickCollectButtonWithButton:)])
    {
        [_delegate releasePersonInfomationDidClickCollectButtonWithButton:_collectButton];
    }
}

-(void)clickBespeakButton
{
    if ([_delegate respondsToSelector:@selector(releasePersonInfomationDidClickAppointmentButtonWithButton:)])
    {
        [_delegate releasePersonInfomationDidClickAppointmentButtonWithButton:_bespeakButton];
    }
}

#pragma mark api
-(void)setCellWithReleasePersonModel:(XMLRealsePersonInformation *)model personType:(XVVReleasePersonInfomationType)useType
{
    informationViewHeight = [XVVReleasePersonInfomation getHeight:model personType:useType];
    [_informationView setData:model personType:XVVReleasePersonInfomationExhibitor];
    [self refreshLayout:self.frame];
}

-(void)setCellButtonWithAppointmentStatus:(NSString *)appointStatus collectStatus:(NSString *)colStatus
{
    if ([colStatus intValue]==1)
    {
        _collectButton.image = [UIImage imageNamed:@"收藏按钮_已点击"];
        _collectButton.text = NSLocalizedString(@"已收藏", nil);
    }
    else
    {
        _collectButton.image = [UIImage imageNamed:@"收藏按钮_未点击"];
        _collectButton.text = NSLocalizedString(@"收藏", nil);
    }
    
    if ([appointStatus intValue]==1)
    {
        _bespeakButton.image = [UIImage imageNamed:@"预约按钮_已点击"];
        _bespeakButton.text = NSLocalizedString(@"已预约", nil);
    }
    else
    {
        _bespeakButton.image = [UIImage imageNamed:@"预约按钮_未点击"];
        _bespeakButton.text = NSLocalizedString(@"预约", nil);
    }
    
    [self refreshLayout:self.frame];
}

+(CGFloat)getHeightWithReleasePersonModel:(XMLRealsePersonInformation *)model personType:(XVVReleasePersonInfomationType)useType
{
    if ([UserInfo shareUserInfo].isExhibitor)
    {
        return [XVVReleasePersonInfomation getHeight:model personType:useType]+10+30;
    }
    return [XVVReleasePersonInfomation getHeight:model personType:useType]+35+10+30;
}

@end
